#include <nds.h>
#include "decoder_meta.h"
#include "debug.h"

extern DecoderMeta decoders;

// ----------------
// open for the playlist
Decoder* DecoderFactory::getDecoderByFile(std::string filepath) {
// ----------------
	Decoder* obj;
	
	#ifdef DEBUG_DEC
	iprintf("Found format: ");
	#endif

	obj = &decoders.flac;
	if ( obj->checkFormat(filepath) ) {
		#ifdef DEBUG_DEC
		iprintf("FLAC\n");
		#endif
		return obj;
	}
	
	obj = &decoders.wave;
	if ( obj->checkFormat(filepath) ) {
		#ifdef DEBUG_DEC
		iprintf("WAVE\n");
		#endif
		return obj;
	}
	
	obj = &decoders.null;
	#ifdef DEBUG_DEC
	iprintf("NULL\n");
	#endif
	return obj;
}

// ----------------
// open for the player
Decoder* DecoderFactory::getDecoderByType(std::string type) {
// ----------------
	Decoder* obj;
	
	if ( type.compare("FLAC") == 0 )
	{
		obj = &decoders.flac;
	}
	else
	if ( type.compare("WAVE") == 0 )
	{
		obj = &decoders.wave;
	}
	else
	{
		obj = &decoders.null;
	}
	return obj;
}
